package com.idheima.zuoye.zuoye3;

import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Test {
    public static void main(String[] args) {
        HashSet<String> hs = new HashSet<>();
        hs.add("王佳乐");
        hs.add("张三丰");
        hs.add("张飞");
        hs.add("王思聪");
        hs.add("刘晓敏");
        hs.add("王敏");
        Set<String> zhang = hs.stream()
                .filter(s -> s.startsWith("张"))
                .limit(2).collect(Collectors.toSet());
        System.out.println("前两个姓张的元素是："+zhang);
        System.out.println("=======");
        Set<String> wang = hs.stream()
                .filter(s -> s.startsWith("王"))
                .skip(1)
                .collect(Collectors.toSet());
        System.out.println("跳过一个姓王的元素是："+wang);
    }
}
